/*
 * @文件描述:获取当前运行系统的硬件信息
 * @版本:
 * @作者:周晨阳
 * @Date:2021-10-31 20:57:47
 */
#include "systemInfo.h"
#include <time.h>
#include <iostream>
#include <JQCPUMonitor>

#ifdef Q_OS_WIN
#include <sysinfoapi.h>
#endif

MainWindow *view;
int threadbit = 1;
SystemInfo::SystemInfo(MainWindow &window)
{
    view = &window;
    window.onViewChangeTitle("CPU");
}

SystemInfo::~SystemInfo()
{
    threadbit = 0;
    this->terminate();
    this->wait();
}
void SystemInfo::run()
{
    while (threadbit)
    {
#ifdef Q_OS_WIN

        MEMORYSTATUSEX statusex;
        statusex.dwLength = sizeof(statusex);
        GlobalMemoryStatusEx(&statusex);
        view->onViewSetMemory(statusex.dwMemoryLoad);
#elif (defined Q_OS_LINUX)

#endif
        view->onViewChangeRelValue((int)(JQCPUMonitor::cpuUsagePercentage() * 100));

        QThread::msleep(500);
    }
}
